/*
 * B.cxx
 *
 *  Created on: 3:41:44 PM Oct 14, 2012
 *  Author: Pallab
 *
 * "I have not failed, I have just found 10000 ways that won't work.
*/

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait(double seconds) {
	double endtime = clock() + (seconds * CLOCKS_PER_SEC);
	while (clock() < endtime) {
		;
	}
}
#define T int
inline T fastIn() {
	register char c = 0;
	register T a = 0;
	while (c < 33)
		c = getchar();
	while (c > 33) {
		a = (a * 10) + (c - '0');
		c = getchar();
	}
	return a;
}
inline int toI(string _str){
    // STRING EMPTY HOTE PARBE NA
    assert( LN(_str) );
    int var;
    sscanf(_str.c_str(),"%d",&var);
return var;
}
string ss;
int command_count;
string com[105];
inline void read() {
	command_count = fastIn();
	foE(i,1,command_count)	{
		cin >> ss;
		if( ss=="SAME"){
			cin>>ss;
			cin>>ss;
			com[i] = com[ toI(ss) ];
		}
		else{
			com[i]=ss;
		}
	}

}
inline void proc() {
	int p=0;
	foE(i,1,command_count){
		p+= ( com[i]=="RIGHT"? +1 : -1 );
	}
	cout<<p<<'\n';
}
int main() {
	int kase = 1;
#if defined( xerxes_pc )
	if (!freopen("B/in1", "r", stdin))
		puts("error opening file B/in1 "), assert(0);
	kase = 1;
#endif
	kase=fastIn();
	fo(i,kase)
	{
		read();
		proc();
	}
	return 0;
}
